<template>
  <el-dialog :title=title :close-on-click-modal="false" :visible.sync="messageShow" class="view">
    <el-form ref="dataForm" :model="form" :rules="dataRule" label-width="150px">
      <el-form-item label="请输入标签名称" prop="tagName">
        <el-input v-model="form.tagName"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="messageShow = false">取消</el-button>
      <el-button type="primary" @click="updataData">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
    export default {
        name: "valueManageTagAdd",
        data () {
            return {
                messageShow: false,
                title: '标签新增',
                form: {},
                id: '',

                dataRule: {
                    tagName: [
                        { required: true, message: "标签名称不能为空", trigger: "blur" }
                    ],
                },
            };
        },
        methods:{
            init (id,tagName) {
                this.title = id ? '标签修改' : '标签新增'
                this.id = id
                this.form = {}
                this.form.tagName = tagName
                this.messageShow = true

            },

            updataData () {

                let data = { ...this.form }

                if(this.id) {
                    data.id = this.id
                }
                this.$refs["dataForm"].validate(valid => {

                    if (valid) {
                        this.$http({
                            url: this.$http.adornUrl("/value/tag/saveOrUpdate"),
                            method: "post",
                            data: this.$http.adornData(data)
                        }).then(({data}) => {
                            if (data.code === 0) {
                                this.messageShow = false
                                this.$emit('freshlist')
                                this.$message({

                                    message: this.id?"修改成功":"添加成功",
                                    type: "success"
                                })

                            }else if (data.code === 500){
                                this.$message({
                                    message: data.msg,
                                    type: "error"
                                })
                            }
                        })
                    }
                })
            },


        }
    }


</script>

<style scoped>

  .el-row{
    font-size: 16px;
    margin: 15px 0;
  }
  .cencontent{
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
  }
  .colcontent{
    -webkit-border-radius: 2px;
    -moz-border-radius: 2px;
    border-radius: 2px;
    background: #f2f2f2;
    width: 31.8%;
    margin-bottom: 25px;
    padding: 15px 15px 5px 15px;
  }
  .title{
    font-size: 17px;
    font-weight: 600;
  }
  .titlefu{
    font-size: 14px;
    margin-top: 18px;
  }
  .cencontent .el-row{
    font-size: 12px;
    margin: 10px 0;
  }

</style>
